package mahjong;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.*;

/** A filter class that determines the legal of a Mahjong game save file.
 */
public class GameFilter extends FileFilter {
	final static String maj = "maj";

	/** Determines whether the given file is a legal mahjong file. */
	public boolean accept(File f) 
	{

		if (f.isDirectory()) 
		{
			return true;
		}

		String s = f.getName();
		int i = s.lastIndexOf('.');

		if (i > 0 &&  i < s.length() - 1) 
		{
			String extension = s.substring(i+1).toLowerCase();
			if (maj.equals(extension)) 
			{
				return true;
			} 
			else 
			{
				return false;
			}
		}

		return false;
	}

	public String getDescription() 
	{
		return "Mahjong Game Files";
	}
}
